<template>
  <div class="hy-echart">
    <div ref="echartDivRef" :style="{ width, height }"></div>
  </div>
</template>

<script setup lang="ts">
import type { EChartsOption } from 'echarts';
import { ref, onMounted, watchEffect } from 'vue';
import { useEchart } from './hooks/useEchart';
const props = withDefaults(
  defineProps<{
    options: EChartsOption;
    width?: string;
    height?: string;
  }>(),
  {
    width: '100%',
    height: '360px'
  }
);
const echartDivRef = ref<HTMLElement>();
onMounted(() => {
  const { setOptions } = useEchart(echartDivRef.value!);
  watchEffect(() => {
    setOptions(props.options);
  });
});
</script>

<style scoped></style>
